﻿using System;
using YAXLib;
using System.Globalization;

namespace RaytracerLib.Resamplers.Filters
{
    public class GaussianFilter : Filter
    {
        private double m_exp;
        private double m_alpha = 0.5;

        [YAXNode]
        public double Alpha
        {
            get
            {
                return m_alpha;
            }
            set
            {
                m_alpha = value;
                m_exp = Math.Exp(-m_alpha * Ray * Ray);
            }
        }

        public override string Name 
        {
            get
            {
                return "Gaussian";
            }
        }

        public GaussianFilter()
            : base(2)
        { 
        }

        public override FilterType FilterType
        {
            get
            {
                return FilterType.Gaussian;
            }
        }

        public override double Evaluate(double a_value)
        {
            if (Math.Abs(a_value) > 2)
                return 0;

            return Math.Exp(-m_alpha * a_value * a_value) - m_exp;
        }

        public override string ToString()
        {
            return String.Format(CultureInfo.InvariantCulture, "Gaussian, Alpha: {0}", Alpha);
        }
    }
}